package eu.news.data.hibernate.pojo;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import eu.news.data.pojo.Comment;
import eu.news.data.pojo.News;

/**
 * 评论
 * @author WZZ
 *
 */
@Entity
@Table(name="comment")
public class HB_Comment extends Comment implements java.io.Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3319219110393983100L;

	/**
	 * 代理主键
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	int id;
	
	/**
	 * 用户姓名,not null
	 */
	@Column(nullable=false)
	String username;
	
	/**
	 * 评论内容,not null
	 */
	@Column(columnDefinition="text",nullable=false)
	String comment;
	
	Date time;
	
	/**
	 * 新闻,not null;
	 */
	@ManyToOne(cascade=CascadeType.ALL,
			targetEntity=HB_News.class,
			fetch=FetchType.LAZY
		)
	@JoinColumn(name="news_id",nullable=false)
	HB_News news;
	
	/**
	 * 回复至
	 */
	@ManyToOne(cascade=CascadeType.ALL,
			targetEntity=HB_Comment.class,
			fetch=FetchType.LAZY
		)
	@JoinColumn(name="replyTo")
	HB_Comment replyTo;

	/**
	 * 回复
	 */
	@OneToMany(cascade=CascadeType.ALL,mappedBy="replyTo",fetch=FetchType.LAZY)
	Set<HB_Comment> replys = new HashSet<HB_Comment>();

	public HB_Comment(){};
	
	public HB_Comment(String username, String comment, HB_News news) {
		super();
		this.username = username;
		this.comment = comment;
		this.news = news;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public News getNews() {
		return news;
	}

	public void setNews(News news) {
		this.news = (HB_News) news;
	}

	public HB_Comment getReplyTo() {
		return replyTo;
	}

	public void setReplyTo(Comment replyTo) {
		this.replyTo = (HB_Comment) replyTo;
	}

	public Set<HB_Comment> getReplys() {
		return replys;
	}

	@SuppressWarnings("unchecked")
	public void setReplys(Set<? extends Comment> replys) {
		this.replys = (Set<HB_Comment>) replys;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}


}
